package com.qf.life;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "LifeSessionServlet",value = "/life")
public class LifeSessionServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //        1.通过 request 对象获取 Session 对象
        HttpSession session = request.getSession();

//        session.setMaxInactiveInterval(10); // 设置 session 的有效期时间  按秒设置

        String newUrl = response.encodeRedirectURL("/WebProject_war_exploded/gets");

        System.out.println(newUrl);

        response.sendRedirect(newUrl);
        System.out.println(session.getId());



    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
